<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */
 
class Admin_LiabilitiesController extends Zenddn_Controller_Action{
	
	public function init(){
		parent::init();
        parent::loadTemplate('alpona');
        $this->view->headTitle = "manage liabilities";
	}
	
	public function indexAction(){
		$scripts = array('jquery.dataTables.js', 'dataTables.bootstrap.js', 'TableTools.js');
		parent::addScripts($scripts);
		$model_dept = new Admin_Model_Dept();
        //$payment = $model_dept->getPayment();
        
        $model = new Admin_Model_Liabilities();
        $dept = $model->getDept();
        $orders = $model->getOrders();
        $payment = $model->getPayment();
        $refund = $model->getRefund();
        $customer_total = $model->getCustomerTotal();
        
        $this->view->customer_total = $customer_total;
        $this->view->refund = $refund;
        $this->view->dept = $dept;
        $this->view->orders = $orders;
        $this->view->payment = $payment;
	}
    
    public function paymentAction(){
        $this->_helper->_viewRenderer->setNoRender();
    	$request = $this->_request;
        
        $validator = new Admin_Form_ValidatePayment($request->getParams());
        $model = new Admin_Model_Dept();
        $model->savePayment($validator->getData());
        
        $this->_helper->_redirector->gotoRoute(array('module' => 'admin', 'controller' => 'liabilities', 'action' => 'index'), null, true);
    }
    
    public function viewDetailAction(){
    	$this->view->headTitle = "detail sell-buy";
    	$scripts = array('jquery.dataTables.js', 'dataTables.bootstrap.js', 'TableTools.js');
		parent::addScripts($scripts);
        
        $request = $this->_request;
        $customer_id = $request->getParam('id', false);
        
        $model = new Admin_Model_SalesInvoice();
        $data = $model->getDatas(array('where' => "o.customer_id = $customer_id"));
        
        $model_dept = new Admin_Model_Dept();
        $dept = $model_dept->getDatas($customer_id);
        $payment = $model_dept->getPayments($customer_id);
        
        $this->view->customer_id = $customer_id;
        $this->view->data = $data;
        $this->view->dept = $dept;
        $this->view->payment = $payment;
    }
    
    public function removePaymentAction(){
    	$request = $this->_request;
        
        $id = $request->getParam('id', false);
        
        if($id){
            $model_dept = new Admin_Model_Dept();
            $model_dept->deletePayment($id);
            
            $id = $request->getParam('customer_id', false);
            
            $this->_helper->_redirector->gotoRoute(array('module' => 'admin', 'controller' => 'liabilities', 'action' => 'view-detail', 'id' => $id), null, true);
        }
        
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
    }
}